package com.lyn.chapter3.demo2;

/**
 * 多线程可用，又避免了锁，但要熟悉静态内部类的语法和特性
 * @author mac
 *
 */
public class StaticHolderSingleton {
	
	//私有构造器
	private StaticHolderSingleton() {
		//什么也不做
	}
	
	//静态内部类
	private static class InstanceHolder {
		final static StaticHolderSingleton INSTANCE = new StaticHolderSingleton();
	}
	
	 public static StaticHolderSingleton getInstance() {
		return InstanceHolder.INSTANCE;
	 }
	 
	 public void someService() {
		 //省略其他代码
	 }
	 
	 public static void main(String[] args) {
		StaticHolderSingleton.getInstance().someService();
	}
}
